import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { WuXingDiceWordItem } from "./WuXingDiceWordItem";
import { SWuXingDice } from "../../../../../Message/Public/SWuXingDice";
import { Cache } from "../../../cache/Cache";
import { GameConst } from "../../../../component/gconst/GameConst";
import { WuXingConfig } from "../../../resource/WuXingConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../../resource/ColorConfig";
type int = number;
//class WuXingDiceWordListPanel
    
    export  class WuXingDiceWordListPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._wordItemArray = [];
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            ObjCreate.createTextField(Language.getString(26222), 0, 0, 200, 30, this, GlobalStyle.textFormat6);
            this._mainTxt = ObjCreate.createTextField("", 72, 0, 200, 30, this, GlobalStyle.textFormat6);
            this._mainTipTxt = ObjCreate.createTextField("", 103, 0, 200, 20, this, GlobalStyle.textFormat8);
            var loc2=0;
            while (loc2 < 6) 
            {
                loc1 = new WuXingDiceWordItem();
                loc1.x = 0 + loc2 * 48;
                loc1.y = 20;
                loc1.wuxing = 0;
                this.addChild(loc1);
                this._wordItemArray.push(loc1);
                ++loc2;
            }
            return;
        }

        public updateBuWuXingDice(arg1: SWuXingDice): void
        {
            this._wxDice = arg1;
            if (arg1) 
            {
                this._mainAttr = Cache.instance.role.wuxingInfo.mainAttribute;
                this._mainAttrName = Cache.instance.role.wuxingInfo.mainAttrName;
                this._mainTxt.htmlText = Cache.instance.role.wuxingInfo.colorMainAttrName;
                this._dices = this.getSortDices(arg1.dice);
                this._freeLeftTime = GameConst.WuxingFreeChangeCount - arg1.toModifyCount;
                this._freeLeftTime = this._freeLeftTime > 0 ? this._freeLeftTime : 0;
                this._cost = WuXingConfig.instance.getChangeEnergyCost(this._wxDice.diceMoneyModifyCount + 1);
                this._mainTipTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(26224, this._mainAttrName), ColorConfig.instance.getWuxingColor(this._mainAttr));
                this.updateWordItem(this._freeLeftTime, this._cost, this._dices);
            }
            return;
        }

        /* internal  */updateWordItem(arg1: int, arg2: int, arg3: Array<any>): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._wordItemArray.length) 
            {
                (loc1 = this._wordItemArray[loc2] as WuXingDiceWordItem).freeLeftTimes = arg1;
                loc1.cost = arg2;
                loc1.wuxing = arg3[loc2] as int;
                ++loc2;
            }
            return;
        }

        /* internal  */getSortDices(arg1: Array<any>): Array<any>
        {
            var loc1=null;
            var loc5=0;
            var loc2=[];
            var loc3=[];
            var loc4=Cache.instance.role.wuxingInfo.mainAttribute;
            var loc6=0;
            while (loc6 < arg1.length) 
            {
                loc5 = arg1[loc6] as int;
                if (loc4 != loc5) 
                {
                    loc3.push(loc5);
                }
                else 
                {
                    loc2.push(loc5);
                }
                ++loc6;
            }
            loc1 = loc2.concat(loc3);
            return loc1;
        }

        /* internal */ static /* const */filterArr: Array<any>=[new Object /* flash.filters.GlowFilter */(268435302, 1, 6, 6, 4)];

        /* internal */ /* var */_mainTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_mainTipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_freeLeftTimeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_isLoaded: Boolean;

        /* internal */ /* var */_wordItemArray: Array<any>;

        /* internal */ /* var */_dices: Array<any>;

        /* internal */ /* var */_wxDice: SWuXingDice;

        /* internal */ /* var */_freeLeftTime: int;

        /* internal */ /* var */_cost: int;

        /* internal */ /* var */_mainAttrName: string;

        /* internal */ /* var */_mainAttr: int;

        /* internal */ /* var */_diceMoneyModifyCount: int;
    }
